package com.ext.aic.apis.user;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.R;
import com.ext.aic.apis.ApiDefine;
import com.ext.aic.apis.ApiPaths;
import com.ext.aic.apis.RequestResponse;
import com.ext.aic.beans.params.PreinstalledLicenseParams;
import com.ext.aic.beans.response.PreinstalledLicenseResponse;
import com.eyinfo.android_pure_utils.utils.JsonUtils;
import com.hjq.http.EasyHttp;
import com.hjq.http.body.JsonRequestBody;
import com.hjq.http.config.IRequestApi;

public class PreinstalledLicenseRequest {

    protected void onPreinstalledLicenseSuccess(PreinstalledLicenseResponse response) {

    }

    protected void onPreinstalledLicenseEnd() {

    }

    public void request(Context context, LifecycleOwner lifecycleOwner, PreinstalledLicenseParams params) {
        EasyHttp.post(lifecycleOwner)
                .api(new ApiDefine(ApiPaths.preinstalledLicense))
                .body(new JsonRequestBody(JsonUtils.toJson(params)))
                .request(new RequestResponse<PreinstalledLicenseResponse>(context, true, R.string.processing) {
                    @Override
                    protected void onSuccess(PreinstalledLicenseResponse response) {
                        onPreinstalledLicenseSuccess(response);
                    }

                    @Override
                    public void onHttpFail(Throwable throwable) {
                        super.onHttpFail(throwable);
                    }

                    @Override
                    public void onHttpEnd(IRequestApi api) {
                        super.onHttpEnd(api);
                        onPreinstalledLicenseEnd();
                    }
                });

    }
}
